import CryptoJS from "crypto-js";
import Base64 from 'base-64';

let tools = {
	/*aes加密*/
	encodeAES(word, keyStr) {
		var key = CryptoJS.enc.Utf8.parse(keyStr);
		var srcs = CryptoJS.enc.Utf8.parse(word);
		var encrypted = CryptoJS.AES.encrypt(srcs, key, {
			mode: CryptoJS.mode.ECB,
			padding: CryptoJS.pad.Pkcs7
		});
		return encrypted.toString();
	},
	/*aes解密*/
	decryptAES(word, keyStr) {
		var key = CryptoJS.enc.Utf8.parse(keyStr);
		var decrypt = CryptoJS.AES.decrypt(word, key, {
			mode: CryptoJS.mode.ECB,
			padding: CryptoJS.pad.Pkcs7
		});
		return CryptoJS.enc.Utf8.stringify(decrypt).toString();

	},
	/*base64加密*/
	encodeBase64(str) {
		var hex = Base64.encode(str); //编码：MTIzNDU2 
		return hex
	},
	/*base64解密*/
	decryptBase64(str) {
		var hex = Base64.decode(str); //编码：MTIzNDU2
		return hex
	}
};

export default tools;
